<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="ElasticSearch,head,SpringData,IK分词器,">










<meta name="description" content="ElasticSearch基础入门及搜索服务的开发">
<meta name="keywords" content="ElasticSearch,head,SpringData,IK分词器">
<meta property="og:type" content="article">
<meta property="og:title" content="ElasticSearch基础入门及搜索服务的开发">
<meta property="og:url" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/index.html">
<meta property="og:site_name" content="babybabywang">
<meta property="og:description" content="ElasticSearch基础入门及搜索服务的开发">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/体系结构.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/ElasticSearch启动成功.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/Restful新建索引库.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/Restful新建文档.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/Restful查询所有.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/Restful修改文档.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/RestFul根据ID查询.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/RestFul基本查询.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/Restful模糊查询.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/RestFul删除文档.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/head连接elasticSearch.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/IK最小切分算法.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/IK最细切分算法.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/IK自定义词库.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/IK配置自定义词库.png">
<meta property="og:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/测试搜索.png">
<meta property="og:updated_time" content="2019-01-24T14:32:06.391Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="ElasticSearch基础入门及搜索服务的开发">
<meta name="twitter:description" content="ElasticSearch基础入门及搜索服务的开发">
<meta name="twitter:image" content="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/体系结构.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/">





  <title>ElasticSearch基础入门及搜索服务的开发 | babybabywang</title>
  








</head>
<!-- С���� <script type="text/javascript" src="/js/src/love.js"></script> -->

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
		<a href="https://github.com/babybabywang" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; left: 0; transform: scale(-1, 1);" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style></a>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">babybabywang</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://www.babywang.huangsm.xyz/2019/01/23/ElasticSearch基础入门及搜索服务的开发/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="huangsm">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blogHead.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="babybabywang">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">ElasticSearch基础入门及搜索服务的开发</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-01-23T20:50:33+08:00">
                2019-01-23
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="/categories/ElasticSearch/" itemprop="url" rel="index">
                    <span itemprop="name">ElasticSearch</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1.5k
                </span>
              

              

              
            </div>
          

          
              <div class="post-description">
                  ElasticSearch基础入门及搜索服务的开发
              </div>
          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h1><h3 id="什么是ElasticSearch"><a href="#什么是ElasticSearch" class="headerlink" title="什么是ElasticSearch"></a>什么是ElasticSearch</h3><pre><code>Elasticsearch是一个实时的分布式搜索和分析引擎。它可以帮助你用前所未有的速度去处理大规模数据。
ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎，基于RESTful 
web接口。Elasticsearch是用Java开发的，并作为Apache许可条款下的开放源码发布，是当前流行的企业级搜索引
擎。设计用于云计算中，能够达到实时搜索，稳定，可靠，快速，安装使用方便。
</code></pre><h3 id="ElasticSearch特点"><a href="#ElasticSearch特点" class="headerlink" title="ElasticSearch特点"></a>ElasticSearch特点</h3><pre><code>（1）可以作为一个大型分布式集群（数百台服务器）技术，处理PB级数据，服务大公司；也可以运行在单机上
（2）将全文检索、数据分析以及分布式技术，合并在了一起，才形成了独一无二的ES；
（3）开箱即用的，部署简单
（4）全文检索，同义词处理，相关度排名，复杂数据分析，海量数据的近实时
</code></pre><h3 id="ElasticSearch体系结构"><a href="#ElasticSearch体系结构" class="headerlink" title="ElasticSearch体系结构"></a>ElasticSearch体系结构</h3><p><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/体系结构.png" alt="ElasticSearch体系结构"></p>
<h1 id="环境准备"><a href="#环境准备" class="headerlink" title="环境准备"></a>环境准备</h1><h3 id="ElasticSearch部署与启动"><a href="#ElasticSearch部署与启动" class="headerlink" title="ElasticSearch部署与启动"></a>ElasticSearch部署与启动</h3><ol>
<li><p>下载ElasticSearch 5.6.8版本</p>
<pre><code>https://www.elastic.co/downloads/past-releases/elasticsearch-5-6-8
</code></pre></li>
<li><p>在命令提示符下，进入ElasticSearch安装目录下的bin目录,执行命令即可启动。</p>
<pre><code>我们打开浏览器，在地址栏输入http://127.0.0.1:9200/ 即可看到输出结果
</code></pre><p><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/ElasticSearch启动成功.png" alt="ElasticSearch启动成功"></p>
<h1 id="不同操作方式使用ElasticSearch"><a href="#不同操作方式使用ElasticSearch" class="headerlink" title="不同操作方式使用ElasticSearch"></a>不同操作方式使用ElasticSearch</h1><h3 id="通过PostMan使用RestFul风格操作ElasticSearch"><a href="#通过PostMan使用RestFul风格操作ElasticSearch" class="headerlink" title="通过PostMan使用RestFul风格操作ElasticSearch"></a>通过PostMan使用RestFul风格操作ElasticSearch</h3></li>
<li><p>新建索引库<br><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/Restful新建索引库.png" alt="Restful新建索引库"></p>
</li>
<li><p>新建文档<br><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/Restful新建文档.png" alt="Restful新建文档"></p>
</li>
<li>查询全部文档<br><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/Restful查询所有.png" alt="Restful查询所有"></li>
<li>修改文档<br><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/Restful修改文档.png" alt="Restful修改文档"><br><br><br><strong>如果ID不存在则重新创建</strong></li>
<li>按ID查询文档<br><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/RestFul根据ID查询.png" alt="RestFul根据ID查询"></li>
<li>基本匹配查询<br><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/RestFul基本查询.png" alt="RestFul基本查询"></li>
<li>模糊查询<br><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/Restful模糊查询.png" alt="Restful模糊查询"></li>
<li>删除文档<br><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/RestFul删除文档.png" alt="RestFul删除文档"><h3 id="Head插件方式操控ElasticSearch"><a href="#Head插件方式操控ElasticSearch" class="headerlink" title="Head插件方式操控ElasticSearch"></a>Head插件方式操控ElasticSearch</h3><h4 id="安装head"><a href="#安装head" class="headerlink" title="安装head"></a>安装head</h4></li>
<li><p>下载head插件</p>
<pre><code>https://github.com/mobz/elasticsearch-head
</code></pre></li>
<li>解压到任意目录，但是要和elasticsearch的安装目录区别开</li>
<li><p>按照node js，按照cnpm</p>
<pre><code>npm install -g cnpm --registry=https://registry.npm.taobao.org
</code></pre></li>
<li><p>将grunt安装为全局命令 。Grunt是基于Node.js的项目构建工具。它可以自动运行你所设定的任务</p>
<pre><code>npm install ‐g grunt‐cli
</code></pre></li>
<li><p>安装依赖</p>
<pre><code>cnpm install
</code></pre></li>
<li><p>进入head目录启动head，在命令提示符下输入命令</p>
<pre><code>grunt server
</code></pre></li>
<li>打开浏览器，输入 <a href="http://localhost:9100" target="_blank" rel="noopener">http://localhost:9100</a></li>
<li><p>点击连接按钮没有任何相应，按F12发现有如下错误</p>
<pre><code>No &apos;Access-Control-Allow-Origin&apos; header is present on the requested resour
这个错误是由于elasticsearch默认不允许跨域调用，而elasticsearch-head是属于前端工程，所以报错。
我们这时需要修改elasticsearch的配置，让其允许跨域访问。

修改elasticsearch配置文件：elasticsearch.yml，增加以下两句命令：
http.cors.enabled: true
http.cors.allow‐origin: &quot;*&quot;
此步为允许elasticsearch跨越访问 点击连接即可看到相关信息
</code></pre><p><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/head连接elasticSearch.png" alt="head连接elasticSearch"></p>
<h3 id="IK分词器的使用"><a href="#IK分词器的使用" class="headerlink" title="IK分词器的使用"></a>IK分词器的使用</h3></li>
<li><p>安装IK分词器<br>下载地址：<a href="https://github.com/medcl/elasticsearch-analysis-ik/releases" target="_blank" rel="noopener">https://github.com/medcl/elasticsearch-analysis-ik/releases</a> 下载5.6.8版<br>本 </p>
<pre><code>（1）先将其解压，将解压后的elasticsearch文件夹重命名文件夹为ik
（2）将ik文件夹拷贝到elasticsearch/plugins 目录下。
（3）重新启动，即可加载IK分词器
</code></pre></li>
<li><p>IK分词器测试<br>IK提供了两个分词算法ik_smart 和 ik_max_word其中ik_smart为最少切分，ik_max_word为最细粒度划分<br>我们分别来试一下</p>
<pre><code>（1）最小切分：在浏览器地址栏输入地址
http://127.0.0.1:9200/_analyze?analyzer=ik_smart&amp;pretty=true&amp;text=我是中国程序员
输出的结果为：
</code></pre><p><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/IK最小切分算法.png" alt="IK最小切分算法"></p>
<pre><code>（2）最细切分：在浏览器地址栏输入地址
http://127.0.0.1:9200/_analyze?analyzer=ik_max_word&amp;pretty=true&amp;text=我是中国程序员
输出结果为:
</code></pre><p><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/IK最细切分算法.png" alt="IK最细切分算法"></p>
</li>
<li><p>IK自定义词库<br>步骤：</p>
<pre><code>（1）进入elasticsearch/plugins/ik/config目录
（2）新建一个my.dic文件，编辑内容
（3）修改IKAnalyzer.cfg.xml（在ik/config目录下）,然后重启elasticsearch服务
</code></pre><p><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/IK自定义词库.png" alt="IK自定义词库"><br><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/IK配置自定义词库.png" alt="IK配置自定义词库"><br><br><br><strong>注意my.dic文件需要存储为UTF-8无BOM格式</strong></p>
<h3 id="JAVA操作ElasticSearch"><a href="#JAVA操作ElasticSearch" class="headerlink" title="JAVA操作ElasticSearch"></a>JAVA操作ElasticSearch</h3></li>
<li>关于索引库文档类概念<ul>
<li>是否索引，就是看该域是否能被搜索</li>
<li>是否分词，就表示搜索的时候是整体匹配还是单词匹配，如果不分词的话代表整句匹配</li>
<li>是否存储，就是是否在页面上显示</li>
</ul>
</li>
<li><p>引入依赖和修改配置文件</p>
<pre><code> &lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-data-elasticsearch&lt;/artifactId&gt;
&lt;/dependency&gt;
修改配置文件:
spring:
  data:
    elasticsearch:
      cluster-nodes: localhost:9300
</code></pre></li>
<li><p>创建索引文档类</p>
<pre><code>/**
 * SpringDataElasticSearch索引库文档类
 * indexName 索引库名称
 * type 数据库类型
 * @author huangsm
 */
@Document(indexName = &quot;tensquare_article&quot;,type = &quot;article&quot;)
@Data
public class Article implements Serializable {
    @Id
    private String id;

    /**
     * index 是否索引，就是看该域是否能被搜索
     * 是否分词，就表示搜索的时候是整体匹配还是单词匹配，如果不分词的话代表整句匹配
     * 是否存储，就是是否在页面上显示
     */
    @Field(index = true,
    analyzer = &quot;ik_smart&quot;,searchAnalyzer = &quot;ik_smart&quot;)
    private String title;
    @Field(index = true,
            analyzer = &quot;ik_smart&quot;,searchAnalyzer = &quot;ik_smart&quot;)
    private String content;
    /**
     * 审核状态
     */
    private String state;
}
</code></pre></li>
<li>编写文章持久层</li>
</ol>
<pre><code>public interface ArticleSearchDao extends ElasticsearchRepository&lt;Article,String&gt; {
    /**
     * 检索
     * @param title
     * @param content
     * @param pageable
     * @return
     */
    public Page&lt;Article&gt;findByTitleOrContentLike(String title,
                                                 String content, Pageable pageable);
}
</code></pre><ol start="5">
<li>编写业务层</li>
</ol>
<pre><code>/**
 * 文章搜索业务
 * @author huangsm
 */
@Service
public class ArticleSearchService {
    @Autowired
    private ArticleSearchDao articleSearchDao;

    @Autowired
    private IdWorker idWorker;
    /**
     * 增加文章
     * @param article
     */
    public void add(Article article){
        article.setId(idWorker.nextId()+&quot;&quot;);
        articleSearchDao.save(article);
    }
    public Page&lt;Article&gt;findByTitleLike(String keywords,int page,int size){
        PageRequest pageRequest = PageRequest.of(page - 1, size);
        return articleSearchDao.findByTitleOrContentLike(keywords,keywords,pageRequest);
    }
}
</code></pre><ol start="6">
<li>编写控制层</li>
</ol>
<pre><code>/**
 * 搜索controller
 *
 * @author huangsm
 */
@RestController
@CrossOrigin
@RequestMapping(&quot;/article&quot;)
public class ArticleController {
    @Autowired
    private ArticleSearchService articleSearchService;

    @PostMapping(&quot;/&quot;)
    public Result save(@RequestBody Article article) {
        articleSearchService.add(article);
        return new Result(true, StatusCode.OK, &quot;操作成功&quot;);
    }

    @GetMapping(value = &quot;/search/{keywords}/{page}/{size}&quot;)
    public Result findByTitleLike(@PathVariable(&quot;keywords&quot;) String keywords,
                                  @PathVariable(&quot;page&quot;) int page, @PathVariable(&quot;size&quot;) int size) {
        Page&lt;Article&gt; pageData = articleSearchService.findByTitleLike(keywords, page, size);
        return new Result(true, StatusCode.OK, &quot;查询成功&quot;, new PageResult&lt;Article&gt;(pageData.getTotalElements(), pageData.getContent()));
    }
}
</code></pre><ol start="7">
<li>测试<br><img src="/2019/01/23/ElasticSearch基础入门及搜索服务的开发/测试搜索.png" alt="测试搜索"></li>
</ol>
<h3 id="ElasticSearch和Solr的对比"><a href="#ElasticSearch和Solr的对比" class="headerlink" title="ElasticSearch和Solr的对比"></a>ElasticSearch和Solr的对比</h3><p><a href="https://www.cnblogs.com/chowmin/articles/4629220.html" target="_blank" rel="noopener">ES和Solr的对比</a></p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>Adhere to the original technology sharing, your support will encourage me to continue to create!</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/wx.jpg" alt="huangsm 微信支付">
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/zfb.jpg" alt="huangsm 支付宝">
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/ElasticSearch/" rel="tag"><i class="fa fa-tag"></i> ElasticSearch</a>
          
            <a href="/tags/head/" rel="tag"><i class="fa fa-tag"></i> head</a>
          
            <a href="/tags/SpringData/" rel="tag"><i class="fa fa-tag"></i> SpringData</a>
          
            <a href="/tags/IK分词器/" rel="tag"><i class="fa fa-tag"></i> IK分词器</a>
          
        </div>
      

      
      
        <div class="post-widgets">
        

        

        
          
          <div id="needsharebutton-postbottom">
            <span class="btn">
              <i class="fa fa-share-alt" aria-hidden="true"></i>
            </span>
          </div>
        
        </div>
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/01/23/SpringDataMongoDB的基本使用及服务开发/" rel="next" title="SpringDataMongoDB的基本使用及服务开发">
                <i class="fa fa-chevron-left"></i> SpringDataMongoDB的基本使用及服务开发
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/01/24/使用Logstash同步ElasticSearch与Mysql数据/" rel="prev" title="使用Logstash同步ElasticSearch与Mysql数据">
                使用Logstash同步ElasticSearch与Mysql数据 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/blogHead.jpg" alt="huangsm">
            
              <p class="site-author-name" itemprop="name">huangsm</p>
              <p class="site-description motion-element" itemprop="description">Make a silk purse out of a self</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">36</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">29</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">104</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://gitee.com/wangyuanbaby" target="_blank" title="Gitee">
                      
                        <i class="fa fa-fw fa-globe"></i>Gitee</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/babybabywang" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-globe"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://blog.csdn.net/weixin_36964056" target="_blank" title="CSDN">
                      
                        <i class="fa fa-fw fa-globe"></i>CSDN</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://gitee.com/wangyuanbaby" title="码云🐴" target="_blank">码云🐴</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.huangsm.xyz:7900/" title="Eureka服务器" target="_blank">Eureka服务器</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#概述"><span class="nav-number">1.</span> <span class="nav-text">概述</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#什么是ElasticSearch"><span class="nav-number">1.0.1.</span> <span class="nav-text">什么是ElasticSearch</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ElasticSearch特点"><span class="nav-number">1.0.2.</span> <span class="nav-text">ElasticSearch特点</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ElasticSearch体系结构"><span class="nav-number">1.0.3.</span> <span class="nav-text">ElasticSearch体系结构</span></a></li></ol></li></ol><li class="nav-item nav-level-1"><a class="nav-link" href="#环境准备"><span class="nav-number">2.</span> <span class="nav-text">环境准备</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#ElasticSearch部署与启动"><span class="nav-number">2.0.1.</span> <span class="nav-text">ElasticSearch部署与启动</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#不同操作方式使用ElasticSearch"><span class="nav-number">3.</span> <span class="nav-text">不同操作方式使用ElasticSearch</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#通过PostMan使用RestFul风格操作ElasticSearch"><span class="nav-number">3.0.1.</span> <span class="nav-text">通过PostMan使用RestFul风格操作ElasticSearch</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Head插件方式操控ElasticSearch"><span class="nav-number">3.0.2.</span> <span class="nav-text">Head插件方式操控ElasticSearch</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#安装head"><span class="nav-number">3.0.2.1.</span> <span class="nav-text">安装head</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#IK分词器的使用"><span class="nav-number">3.0.3.</span> <span class="nav-text">IK分词器的使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#JAVA操作ElasticSearch"><span class="nav-number">3.0.4.</span> <span class="nav-text">JAVA操作ElasticSearch</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ElasticSearch和Solr的对比"><span class="nav-number">3.0.5.</span> <span class="nav-text">ElasticSearch和Solr的对比</span></a></li></ol></li></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; 2018 &mdash; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">HUANGSM</span>

  
</div>









        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    
      <div id="needsharebutton-float">
        <span class="btn">
          <i class="fa fa-share-alt" aria-hidden="true"></i>
        </span>
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  
  
  <link rel="stylesheet" href="/lib/needsharebutton/needsharebutton.css">

  
  
  <script src="/lib/needsharebutton/needsharebutton.js"></script>

  <script>
    
      pbOptions = {};
      
          pbOptions.iconStyle = "box";
      
          pbOptions.boxForm = "horizontal";
      
          pbOptions.position = "bottomCenter";
      
          pbOptions.networks = "Weibo,Wechat,Douban,QQZone,Twitter,Facebook";
      
      new needShareButton('#needsharebutton-postbottom', pbOptions);
    
    
      flOptions = {};
      
          flOptions.iconStyle = "box";
      
          flOptions.boxForm = "horizontal";
      
          flOptions.position = "middleRight";
      
          flOptions.networks = "Weibo,Wechat,Douban,QQZone,Twitter,Facebook";
      
      new needShareButton('#needsharebutton-float', flOptions);
    
  </script>

  

  

  

  

</body>
</html>
